﻿using System;
using System.Collections.Generic;
using System.Text;
using Rect = SDL2.SDL.SDL_Rect;
using Color = SDL2.SDL.SDL_Color;
namespace BITUI.Element
{



    public struct LimitRect
    {
        public int xmin;
        public int ymin;
        public int xmax;
        public int ymax;
    }
    public enum TileRenderScale
    {
        Less1_8 = -8,
        Less1_4 = -4,
        Less1_2 = -2,
        One = 1,
        X2 = 2,
        X4 = 4,
        X8 = 8,
    }
    public interface IWindowRender
    {
        int GetLimitRectDepth();
        void PushLimitTileRect(LimitRect rect);
        LimitRect? PopLimitTileRect();

        LimitRect? CurrentLimitTileRect
        {
            get;
        }

        void DrawTile(Tile.RenderTile tile, int x, int y, byte colorReplace = 0, float scalex = 1.0f, float scaley = 1.0f);
        void DrawTex(IntPtr tex, Rect srcRect, int x, int y, Color color, float scalex = 1.0f, float scaley = 1.0f);
        void DrawTileByNames(Tile.Bank bank, string[] names, int x, int y, byte colorReplace = 0, float scale = 1.0f);
        void DrawTileByNames(Tile.Bank bank, IEnumerable<char> names, int x, int y, byte colorReplace = 0, float scale = 1.0f);
    }
    public interface IWindowEvent
    {
        IElementWithEvent elementPointOver
        {
            get;
        }
        IElementWithEvent elementFocus
        {
            get;
        }
        void RegPointOver(IElementWithEvent ele);
        void RegFocus(IElementWithEvent ele);

        void SetTextInput(int x1, int y1, int x2, int y2);
        void CloseTextInput();
    }


    public interface IElement2D
    {
        IElement2DGroup Parent
        {
            get;
        }
        void SetParent(IElement2DGroup parent);

        int TileXLocal
        {
            get;
            set;
        }
        int TileYLocal
        {
            get;
            set;
        }
        int TileX
        {
            get;
        }
        int TileY
        {
            get;
        }
        int TileWidth
        {
            get;
        }
        int TileHeight
        {
            get;
        }
        void OnDraw(IWindowRender render);

    }
    public interface IElementWithEvent
    {
        //这些是冒泡的
        bool OnMouseDown(IWindowEvent win, byte button);
        bool OnMouseMove(IWindowEvent win, int x, int y);

        bool OnMouseWheel(IWindowEvent win, uint dir, int x, int y);


        //这两个不冒泡
        void OnMouseUp(IWindowEvent win, byte button);

        void OnInput(IWindowEvent win, string text);

        void OnKey(IWindowEvent win, SDL2.SDL.SDL_Scancode key, bool press);
        //这两个是直接通知的
        void OnMouseLeave(IWindowEvent win);
        void OnLostFocus(IWindowEvent win);
        //void OnMouseIn();//这是主动判断的
    }
    //这个接口的意义是让我们标记那些允许改变尺寸的组件，布局时用
    public interface IElement2D_Resizeable : IElement2D
    {
        new int TileWidth
        {
            get;
            set;
        }
        new int TileHeight
        {
            get;
            set;
        }
    }
    //这个接口的意义是 能够作为容器的组件，他们可以自由放置多个其它组件 比如各种Panel
    //特殊放置组件的组件不需要继承IElement2DGroup
    public interface IElement2DGroup : IElement2D, IElementWithEvent

    {
        IReadOnlyList<IElement2D> children
        {
            get;
        }
        void AddChild(IElement2D element);
        void RemoveChild(IElement2D element);

        void OnParentResize(int tileWidth, int tileHeight);
        bool Fill
        {
            get;
            set;
        }
        int BorderRightLocal
        {
            get;
            set;
        }
        int BorderBottomLocal
        {
            get;
            set;
        }
    }


}
